﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ResourceEditor.Core.ResourceDataObjects
{
    public class Data<T> : IEnumerable<T>
    {
        #region Properties
        public string Key { get; internal set; }
        public List<T> Items { get; private set; }
        public ItemState State { get; internal set; }

        public T Current
        {
            get
            {
                return Items.First();
            }
        }

        #endregion

        #region Ctor
        public Data(string key, T item, ItemState state)
        {
            Items = new List<T>() { item };
            Key = key;
            State = state;
        }
        #endregion

        #region Methods
        internal void ChangeItem(T item)
        {
            if (State == ItemState.Original)
            {
                State = ItemState.Modified;
            }

            if (Items.Contains(item))
            {
                Items.Remove(item);
            }

            Items.Insert(0, item);
        }

        internal void ChangeKey(string key)
        {
            if (State == ItemState.Original)
            {
                State = ItemState.Modified;
            }

            Key = key;
        }
        #endregion

        #region IEnumerable<T> Members

        public IEnumerator<T> GetEnumerator()
        {
            return Items.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion
    }
}
